package com.kzf.service.impl;

import com.kzf.mapper.EmpMapper;
import com.kzf.mapper.StudentMapper;
import com.kzf.pojo.JobOption;
import com.kzf.pojo.StudentCount;
import com.kzf.service.ReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    private static final Logger log = LoggerFactory.getLogger(ReportServiceImpl.class);
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobData() {
        //1. 调用mapper接口, 获取统计数据
        //这里List中的每一个元素是一个Map集合，而不是一个键值对，一个Map集合中有多个键值对
        List<Map<String, Object>> list = empMapper.countEmpJobData(); //map: pos=教研主管, num=1

        //2. 组装结果, 并返回
        //通过流来遍历List中的每一个Map集合，这里定义每一个集合形参名为dataMap，取出每一个Map集合中的key为pos对应
        //的value值，然后将这些value值通过toList()来封装回一个List
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();

        //同上，这里是取出每个集合中key为num的value值，将其封装
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new JobOption(jobList, dataList);
    }


    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public List<Map<String,Object>> getStudentDegreeData(){
        return studentMapper.getStudentDegreeData();
    }

    @Override
    public StudentCount getStudentCountData(){
        List<Map<String,Object>> list = studentMapper.getStudentCountData();
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("className")).toList();
        log.info(clazzList.toString());
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("studentCount")).toList();
        log.info(dataList.toString());
        return new StudentCount(clazzList,dataList);

    }
}
